import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:search_people/entrance/route/routes.dart';
import 'package:search_people/page/dynamic/subs/dynamic_leaders/dynamic_leaders.dart';
import 'package:search_people/page/dynamic/subs/subscribe/view.dart';
import 'package:search_people/utils/component/component.dart';
import 'package:search_people/value/topcolors.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class DynamicPage extends StatelessWidget {
  DynamicPage({Key? key}) : super(key: key);
  final controller = Get.put(DynamicController());
  final state = Get.find<DynamicController>().state;
  // 主视图
  Widget _buildView() {
    return TabBarView(
      controller: state.tc,
      children: state.titles
          .asMap()
          .map(
            (key, value) => MapEntry(
              key,
              key == 0 ? SubscribePage() : DynamicLeaderPage(),
            ),
          )
          .values
          .toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DynamicController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.white,
            leading: TPTabBar(
              tabCtrl: state.tc,
              tabTitles: state.titles,
            ),
            leadingWidth: Get.width - 45.r,
            actions: [
              IconButton(
                  onPressed: () {
                    Get.toNamed(RouterPath.dynamic_search);
                  },
                  icon: Icon(
                    Icons.search,
                    color: TopColors.black_66,
                  ))
            ],
            elevation: 0.2,
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
